package com.zjitc;

import com.google.gson.*;

import java.lang.reflect.Type;
import java.sql.Timestamp;
import java.time.LocalDateTime;

/**
 * Created by lenovo on 2018/4/1.
 */
public class GsonOfDate implements JsonSerializer<LocalDateTime>, JsonDeserializer<LocalDateTime> {

    public static Gson getInstance() {
        return new GsonBuilder()
                .registerTypeAdapter(LocalDateTime.class, new GsonOfDate())
                .create();
    }

    @Override
    public LocalDateTime deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
            throws JsonParseException {
        return null;
    }

    @Override
    public JsonElement serialize(LocalDateTime src, Type typeOfSrc, JsonSerializationContext context) {
        return new JsonPrimitive(Timestamp.valueOf(src).getTime());
    }
}
